<?php

namespace app\common\model\xiluedu;

use app\common\library\Auth;
use think\Model;


class SignRule extends Model
{

    

    

    // 表名
    protected $name = 'xiluedu_sign_rule';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];
    

    

    //根据连续签到时间获取积分
    public static function getSignScore($series_days){
        $max_sign = (new SignRule())->order('day','desc')->find();
        if($max_sign['day']>=$series_days){
            $where['day'] = $series_days;
        }else{
            $where['day'] = $max_sign['day'];
        }
        $auth = Auth::instance();
        $user_vip = UserVip::where('user_id',$auth->id)->where('expire_time','>=',strtotime(date('Y-m-d')))->find()?:[];
        $field = $user_vip ?'vip_score' : 'score';
        return SignRule::where($where)->value($field);
    }




}
